package dao

import (
	"ssims/models"
)

func GetAllGener(gener map[string]interface{}) (error, []models.Gener, int64) {
	var generData []models.Gener
	page := gener["page"].(int)
	pageSize := gener["limit"].(int)
	searchName := gener["searchName"].(string)
	var total int64
	err := db.Table("gener").Select("gen_id, gen_name, gen_father, gen_mother, gen_no").Where("gen_name like ? and is_del = false", searchName+"%").Order("gen_id ASC").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&generData).Error
	return err, generData, total
}
func GetNumbers(gener map[string]interface{}) (error, []models.Tji, int64) {
	var numbersDate []models.Tji
	// page := sc["page"].(int)
	// pageSize := sc["limit"].(int)
	//searchName := sc["searchNo"].(int)
	var total int64
	err := db.Table("gener").Select("gen_no, COUNT(gen_no)").Group("gen_no").Count(&total).Find(&numbersDate).Error
	return err, numbersDate, total
}
func DelGener(gen_id string) error {
	err := db.Table("gener").Where("gen_id = ?", gen_id).Update("is_del", true).Error
	return err
}

func UpdateGener(gener models.Gener) error {
	err := db.Table("gener").Where("gen_id = ?", gener.GenId).Updates(&gener).Error
	return err
}

func AddGener(gener models.Gener) error {
	err := db.Table("gener").Select("gen_id", "gen_name", "gen_father", "gen_mother", "gen_no", "is_del").Create(&gener).Error
	return err
}
